package flex.cc.drive.controller;

import com.alibaba.fastjson.JSONObject;
import flex.cc.basicinformation.entity.ServiceConfigEntity;
import flex.cc.basicinformation.service.ServiceConfigService;
import flex.cc.core.support.BaseController;
import flex.cc.drive.dto.OrderDriveVo;
import flex.cc.drive.service.CheckScopeService;
import flex.cc.drive.service.DriverCancelService;
import flex.cc.drive.service.OrderDriverService;
import flex.cc.system.service.DictCodeService;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wkangle
 * @className DriveServiceController
 * @description 代驾服务模块
 * @time 2022-01-18 16:00:03
 */
@SuppressWarnings("restriction")
@RestController
@RequestMapping(value = "/vehicleSvr/driveService/wechat")
public class DriveServiceController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(DriveServiceController.class);

    @Autowired
    private CheckScopeService checkScopeService;
    @Autowired
    private OrderDriverService orderDriverService;
    @Autowired
    private DriverCancelService driverCancelService;
    @Autowired
    private DictCodeService dictCodeService;
    @Autowired
    private ServiceConfigService serviceConfigService;



    @PostMapping(value = "/checkScope")
    @ApiOperation(httpMethod = "POST", value = "校验服务范围")
    public Wrapper<JSONObject> checkScope(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("DriveServiceController -- checkScope() ====> {}", reqVo);
        JSONObject checkScope = checkScopeService.checkScope(reqVo);
        return WrapMapper.ok(checkScope);
    }

    @PostMapping(value = "/drivingSave")
    @ApiOperation(httpMethod = "POST", value = "预约代驾提交")
    public Wrapper<JSONObject> drivingSave(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("DriveServiceController -- drivingSave() ====> {}", reqVo);
        JSONObject drivingSave = orderDriverService.createOrUpdateBespeakOrder(reqVo);
        System.out.println(drivingSave);
        return WrapMapper.ok(drivingSave);
    }

    // TODO
    @PostMapping(value = "/drivingProgress")
    @ApiOperation(httpMethod = "POST", value = "代驾服务进展")
    public Wrapper<OrderDriveVo> drivingProgress(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("DriveServiceController -- drivingProgress() ====> {}", reqVo);
        OrderDriveVo orderDriveVo = orderDriverService.drivingProgress(reqVo);
        return WrapMapper.ok(orderDriveVo);
    }

    // TODO
    @PostMapping(value = "/drivingCancel")
    @ApiOperation(httpMethod = "POST", value = "取消代驾")
    public Wrapper<Map<String, String>> drivingCancel(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, String> reqVo) {
        logger.info("DriveServiceController -- drivingCancel() ====> {}", reqVo);
        Map<String, String> drivingCancel = driverCancelService.driverCancel_V2(reqVo);
        return WrapMapper.ok(drivingCancel);
    }

    /**
     * @description 根据服务项目id查询服务项目的使用规则【2.2-服务包配置需求】
     * @param activityId 服务项目编号
     * @return
     * @author wkangle
     * @time 2022/03/02 0002 14:13
     * @exception/throws
     */
    @GetMapping(value = "/showCouponCancelRule")
    @ApiOperation(httpMethod = "GET", value = "代驾卡券取消说明")
    public Wrapper<ServiceConfigEntity> showCouponCancelRule(@ApiParam(name = "reqVo", value = "请求信息") @RequestParam(name = "activityId") String activityId) {
        logger.info("DriveServiceController -- showCouponCancelRule() ====> {}", activityId);
        //Map<String, Object> dictCodeParams = new HashMap<String, Object>();
        //dictCodeParams.put("typeCode", "couponCancelRule");
        //dictCodeParams.put("value1", activityId);
        //List<DictCodeEntity> list = dictCodeService.queryDictCodeListByParams(dictCodeParams);
        //return WrapMapper.ok(list);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("status", '0');
        params.put("serviceCode", activityId);
        ServiceConfigEntity serviceConfigEntity = serviceConfigService.getOneByParams(params);
        return WrapMapper.ok(serviceConfigEntity);
    }

}
